import { _decorator, Button, Component, Node } from 'cc';
import { UserInfo } from './UserInfo';
import { Start } from './Start';
const { ccclass, property } = _decorator;

@ccclass('SignPanel')
export class SignPanel extends Component {

    @property(Node)
    itemRootNode: Node;

    init() {
        for (let i = 0; i < 7; i++) {
            this.itemRootNode.children[i].getComponent(Button).enabled=false;
            this.itemRootNode.children[i].getChildByName('gou').active=false;

            if (i<=UserInfo.signContinuousDayNum) {
                this.itemRootNode.children[i].getChildByName('gou').active=true;
            }
        }

        if (UserInfo.signContinuousDayNum + 1 <= 6) {
            this.itemRootNode.children[UserInfo.signContinuousDayNum + 1].getComponent(Button).enabled = true;
        }

    }

    onclickSignBtn(event, index) {
        switch (index) {
            case "0":
                if (!UserInfo.todayAlreadyIsSign) {
                    UserInfo.diamondNum +=50;
                    UserInfo.todayAlreadyIsSign=true;
                    UserInfo.signContinuousDayNum+=1;
                    Start.ins.createWindowTip("获得50钻石");
                    Start.ins.saveGameData();
                    this.init();
                }
                else{
                    Start.ins.createWindowTip("今天已经签过到了，明天再来吧");
                }
              
                break;
            case "1":
                if (!UserInfo.todayAlreadyIsSign) {
                    UserInfo.diamondNum +=100;
                    UserInfo.todayAlreadyIsSign=true;
                    UserInfo.signContinuousDayNum+=1;
                    Start.ins.createWindowTip("获得100钻石");
                    Start.ins.saveGameData();
                    this.init();
                }
                else{
                    Start.ins.createWindowTip("今天已经签过到了，明天再来吧");
                }
                break;
            case "2":
                if (!UserInfo.todayAlreadyIsSign) {
                    UserInfo.diamondNum +=200;
                    UserInfo.todayAlreadyIsSign=true;
                    UserInfo.signContinuousDayNum+=1;
                    Start.ins.createWindowTip("获得200钻石");
                    Start.ins.saveGameData();
                    this.init();
                }
                else{
                    Start.ins.createWindowTip("今天已经签过到了，明天再来吧");
                }
                break;
            case "3":
                if (!UserInfo.todayAlreadyIsSign) {
                    UserInfo.diamondNum +=300;
                    UserInfo.todayAlreadyIsSign=true;
                    UserInfo.signContinuousDayNum+=1;
                    Start.ins.createWindowTip("获得300钻石");
                    Start.ins.saveGameData();
                    this.init();
                }
                else{
                    Start.ins.createWindowTip("今天已经签过到了，明天再来吧");
                }
                break;
            case "4":
                if (!UserInfo.todayAlreadyIsSign) {
                    UserInfo.diamondNum +=400;
                    UserInfo.todayAlreadyIsSign=true;
                    UserInfo.signContinuousDayNum+=1;
                    Start.ins.createWindowTip("获得400钻石");
                    Start.ins.saveGameData();
                    this.init();
                }
                else{
                    Start.ins.createWindowTip("今天已经签过到了，明天再来吧");
                }
                break;
            case "5":
                if (!UserInfo.todayAlreadyIsSign) {
                    UserInfo.diamondNum +=500;
                    UserInfo.todayAlreadyIsSign=true;
                    UserInfo.signContinuousDayNum+=1;
                    Start.ins.createWindowTip("获得500钻石");
                    Start.ins.saveGameData();
                    this.init();
                }
                else{
                    Start.ins.createWindowTip("今天已经签过到了，明天再来吧");
                }
                break;
            case "6":
                if (!UserInfo.todayAlreadyIsSign) {
                    UserInfo.diamondNum +=1000;
                    UserInfo.todayAlreadyIsSign=true;
                    UserInfo.signContinuousDayNum+=1;
                    Start.ins.createWindowTip("获得1000钻石");
                    Start.ins.saveGameData();
                    this.init();
                }
                else{
                    Start.ins.createWindowTip("今天已经签过到了，明天再来吧");
                }
                break;

            default:
                break;
        }
    }

}


